package main

import (
	"context"
	"log"
	"os"

	"github.com/olivere/elastic/v7"
)

const goodMapping = `
{
	"mappings":{
		"properties":{
			"name":{
				"type":"text",
				"analyzer": "ik_max_word"
			},
			"id":{
				"type":"integer"
			}
		}
	}
}`

func main() {
	url := "http://120.24.67.46:9200"
	// 打印elasticsearch的执行语句
	logger := log.New(os.Stdout, "myshop", log.LstdFlags)
	client, err := elastic.NewClient(
		elastic.SetURL(url),
		elastic.SetSniff(false),
		elastic.SetTraceLog(logger),
	)
	if err != nil {
		panic(err)
	}

	// Create a new index.
	createIndex, err := client.CreateIndex("mygoods").BodyString(goodMapping).Do(context.Background())
	if err != nil {
		// Handle error
		panic(err)
	}
	if !createIndex.Acknowledged {
		// Not acknowledged
	}
}
